<template>
	<el-form class="login-content-form">
		<el-form-item>
			<el-input
				type="text"
				placeholder="请输入用户名"
				prefix-icon="el-icon-user"
				v-model="ruleForm.account"
				clearable
				autocomplete="off"
			></el-input>
		</el-form-item>
		<el-form-item>
			<el-input
				:type="isShowPassword ? 'text' : 'password'"
				placeholder="请输入密码"
				prefix-icon="el-icon-lock"
				v-model="ruleForm.password"
				autocomplete="off"
			>
				<template #suffix>
					<i
						class="iconfont el-input__icon login-content-password"
						:class="isShowPassword ? 'icon-yincangmima' : 'icon-xianshimima'"
						@click="isShowPassword = !isShowPassword"
					></i>
				</template>
			</el-input>
		</el-form-item>
		<el-form-item>
			<el-button
				type="primary"
				class="login-content-submit"
				@click="onSignIn">
				<span>登 录</span>
			</el-button>
		</el-form-item>
	</el-form>
</template>

<script lang="ts">
import { toRefs, reactive, defineComponent, defineComponent } from 'vue';
export default defineComponent({
	name: 'login',
	setup(props: any, context: any) {
		const state = reactive({
			isShowPassword: false,
			ruleForm: {
				account: '',
				password: ''
			}
		});
		// 此操作只是弹出人机交互验证页面，验证成功后才是真正的调用登录接口
		const onSignIn = () => {
			if (state.ruleForm.account.length > 0 && state.ruleForm.password.length > 1) {
				context.emit("sendCaptChar", {
					show: true,
					account: state.ruleForm.account,
					password: state.ruleForm.password
				});
			}
		};
		return {
			onSignIn,
			...toRefs(state)
		};
	},
});
</script>

<style scoped lang="scss">
.login-content-form {
	margin-top: 20px;
	.login-content-password {
		display: inline-block;
		width: 25px;
		cursor: pointer;
		&:hover {
			color: #909399;
		}
	}
	.login-content-code {
		display: flex;
		align-items: center;
		justify-content: space-around;
		.login-content-code-img {
			width: 100%;
			height: 40px;
			line-height: 40px;
			background-color: #ffffff;
			border: 1px solid rgb(220, 223, 230);
			color: #333;
			font-size: 16px;
			font-weight: 700;
			letter-spacing: 5px;
			text-indent: 5px;
			text-align: center;
			cursor: pointer;
			transition: all ease 0.2s;
			border-radius: 4px;
			user-select: none;
			&:hover {
				border-color: #c0c4cc;
				transition: all ease 0.2s;
			}
		}
	}
	.login-content-submit {
		width: 100%;
		letter-spacing: 2px;
		font-weight: 300;
		margin-top: 15px;
		height: 40px;
	}
	.cain {
		display: flex;
		flex-direction: row;
		justify-content: center;
		align-content: center;
		align-items: center;
	}
}
</style>
